#include<bits/stdc++.h>
using namespace std;

int T;
int n;
int a[200015];
int pos[1000005];

int ans=INT_MIN;

void dfs(int depth,int score,int last_rd,int last_bl){
	if(depth>n){
		ans=max(ans,score);
		return;
	}
	if(a[depth]==a[last_rd]) dfs(depth+1,score+a[depth],depth,last_bl);
	else dfs(depth+1,score,depth,last_bl);
	if(a[depth]==a[last_bl]) dfs(depth+1,score+a[depth],last_rd,depth);
	else dfs(depth+1,score,last_rd,depth);
	return;
}

int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		ans=INT_MIN;
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
		}
		dfs(1,0,0,0);
		printf("%d\n",ans);
	}

	return 0;
}